#pragma once

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <functional>

void func1()
{
    std::cout<<"***** 打开数据库 *****"<<std::endl;
}

void func2()
{
    std::cout<<"***** 打开日志 *****"<<std::endl;
}

void func3()
{
    std::cout<<"***** 运行Hello World *****"<<std::endl;
}

class TaskManager
{
public:
    TaskManager()
    {
        srand(time(nullptr));
    }

    void RegisterTask(std::function<void()> f)
    {
        _tasks.push_back(f);
    }

    int Code()
    {
        return rand() % _tasks.size();
    }

    void ExecuteTask(int code)
    {
        if(code >= 0 && code < _tasks.size())
            _tasks[code]();
    }

private:
    std::vector<std::function<void()>> _tasks;
};